<template>
    <div >中层领导干部信息上传</div>
    <el-upload
            :show-file-list="false"
            :before-upload="beforeUpload"
            :on-success="onSuccess"
            :on-error="onError"
            :disabled="importDisabled"
            style="display: inline-flex;margin-right: 10px;"
            :action="'http://localhost:8080/data/importMi?user='+store.auth.user">
        <el-button size="small" :disabled="importDisabled" type="success">
            <el-icon class="el-icon--left"><Upload /></el-icon>{{importDataText}}
            <div slot="tip" class="el-upload__tip">说明：只能上传xls或xlsx文件</div>
        </el-button>
    </el-upload>

    <div >普通员工资料上传</div>
    <el-upload
            :show-file-list="false"
            :before-upload="beforeUpload"
            :on-success="onSuccess"
            :on-error="onError"
            :disabled="importDisabled1"
            style="display: inline-flex;margin-right: 10px;"
            :action="'http://localhost:8080/data/importOr?user='+store.auth.user">
        <el-button size="small" :disabled="importDisabled1" type="success">
            <el-icon class="el-icon--left"><Upload /></el-icon>{{importDataText1}}
            <div slot="tip" class="el-upload__tip">说明：只能上传xls或xlsx文件</div>
        </el-button>
    </el-upload>

    <div>根据部门人数导出普通员工文件(用户名，部门，密码)</div>
   <div><el-button type="success" @click="outport()">导出</el-button></div>
    <div style="margin-top:20px">
        <el-button type="success" @click="startVote">开始投票</el-button>
        <el-button type="success" @click="closeVote">停止投票</el-button>
    </div>
    <div>
        <el-form :model="stu">
        领导投票中层占比：<el-input placeholder="0.3" v-model="stu.lrate" type="text" style="width:100px"/>
        普通职工投票中层占比：<el-input placeholder="0.7" v-model="stu.orate" type="text" style="width:100px"/>
            <el-button type="primary" @click="send">确定</el-button>
        </el-form>
        <el-form :model="stu1">
            领导投票领导班子占比：<el-input placeholder="0.3" v-model="stu1.lrate" type="text" style="width:100px"/>
            普通职工投票领导班子占比：<el-input placeholder="0.7" v-model="stu1.orate" type="text" style="width:100px"/>
            <el-button type="primary" @click="send1">确定</el-button>
        </el-form>
    </div>
</template>
<script setup>
import { get,post } from '@/utils/request.js'
import {ElMessage} from 'element-plus'
import router from '@/router'
import { ref,onMounted,reactive } from 'vue'
import {userStore} from '@/stores/counter.js'
import {Upload} from '@element-plus/icons-vue'
import moment from 'moment'

const importDataText=ref('导入数据')
const importDisabled=ref(false)
const importDataText1=ref('导入数据')
const importDisabled1=ref(false)
const store=userStore()
const datas=ref([])
const dialogVisible=ref(false)
const imageUrl=ref('')

const stu1 = reactive({
lrate:'',
orate:'',
})

const stu = reactive({
lrate:'',
orate:'',
})

get('/user/getData',(message)=>{
datas.value=message.map(item=>({
     ...item,
     uploadTime: moment(item.uploadTime).format('YYYY-MM-DD HH:mm:ss')
}))
},(message)=>{
ElMessage.warning("failure atain");
})

const onError=()=>{
                importDataText.value = '导入数据';
                this.importDisabled.value = false;
                this.$message.success("导入失败！");
            }
            const onSuccess=()=> {
            	// 成功后文本修改为原来的导入数据
                importDataText.value = '导入数据';
                // 将上传组件改为允许使用
                importDisabled.value = false;
                // 调用刷新数据的方法

                // message 弹出消息
                ElMessage.success("导入成功！");
            }
const beforeUpload=()=> {
            	// 将文本修改为正在导入
                importDataText.value = '正在导入';
                // 将其上传组件暂时禁用
                importDisabled.value = true;
            }

            const getPictureByName=(filename)=>{
            dialogVisible.value=true
            imageUrl.value='http://localhost:8080/picture?name='+filename
            }

            const outport=()=>{
            window.open('http://localhost:8080/user/outport')
            }

            const startVote=()=>{
            get('/vote/startVote',(message)=>{
             ElMessage.success(message);
            },(message)=>{
             ElMessage.warning(message)
            })
            }

            const closeVote=()=>{
            get('/vote/closeVote',(message)=>{
             ElMessage.success(message);
            },(message)=>{
             ElMessage.warning(message)
            })
            }

            const send=()=>{
            post('/download/rate',{
            lrate:stu.lrate,
            orate:stu.orate
            },(message)=>{
             ElMessage.success(message);
            },(message)=>{
             ElMessage.warning(message)
            })
            }

            const send1=()=>{
            post('/download/leaderrate',{
            lrate:stu1.lrate,
            orate:stu1.orate
            },(message)=>{
             ElMessage.success(message);
            },(message)=>{
             ElMessage.warning(message)
            })
            }

</script>
<style scoped>



</style>